let repair = require('../../../api/ca_repair.js');
let that = null;
Page({

    /**
     * 页面的初始数据
     */
    data: {
        repair_tabel: [],// 维修列表
        currentPage: 0,// 页面数
        loadMore: false, //"上拉加载"的变量，默认false，隐藏  
        loadAll: false, //“没有数据”的变量，默认false，隐藏  
    },

    /**
     * 生命周期函数--监听页面加载
     */
    async onLoad(options) {
        that = this;
        wx.showLoading({
            title: '数据加载中...',
            mask: true,
        })
        const user = wx.getStorageSync('user');
        await repair.getRepair_tabel({ _openid: user._openid }, that.data.currentPage, that);
        that.setData({
            _openid: user._openid,
            currentPage: that.data.currentPage + 1,
        })
        wx.hideLoading({
            success: (res) => { console.log('数据加载完成') },
        })
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    async onReachBottom() {
        console.log('上拉触底');
        // 判断是否加载更多
        if (!that.data.loadMore && !that.data.loadAll) {
            that.setData({
                loadMore: true, //加载中  
                loadAll: false //是否加载完所有数据
            });
            await repair.getRepair_tabel({ _openid: that.data._openid }, that.data.currentPage, that);
            that.setData({
                currentPage: that.data.currentPage + 1,
            })
        }
    },

    /**
     * 跳转到维修信息详情页
     * @param {repair} e 
     */
    navigateToRepairDetail(e) {
        const repair = JSON.stringify(e.currentTarget.dataset.repair);
        wx.navigateTo({
            url: '../repairDetail/repairDetail?repair=' + repair,
        })
    },

    /**
     * 右上角分享
     */
    onShareAppMessage() {
        return {
            title: '首页',
            path: '/pages/CA/home/home',
            imageUrl: '../../../images/share.png'
        }
    },
})